<template>
  <div>
    <el-form label-width="120px" v-model="truckForm">
      <el-form-item label="车辆类型:">
        <el-select v-model="truckForm.truckTypeId" placeholder="请选择">
          <el-option v-for="(item,index) in truckTypeData" :label="item.name" :key="index" :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="所属车队:">
        <el-select v-model="truckForm.fleetId" placeholder="请选择">
          <el-option v-for="(item,index) in fleetData" :label="item.name" :key="index" :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="车牌号码:">
        <el-input v-model="truckForm.licensePlate"/>
      </el-form-item>
      <el-form-item label="品牌">
        <el-input v-model="truckForm.brand"/>
      </el-form-item>
      <el-form-item label="GPS设备ID:">
        <el-input v-model="truckForm.deviceGpsId"/>
      </el-form-item>
      <el-form-item label="准载重量(千克):">
        <el-input v-model="truckForm.allowableLoad" type="number"/>
      </el-form-item>
      <el-form-item label="准载体积(方):">
        <el-input v-model="truckForm.allowableVolume" type="number"/>
      </el-form-item>
      <el-form-item label="状态">
        <el-radio v-model="truckForm.status" :label="1" border>正常</el-radio>
        <el-radio v-model="truckForm.status" :label="0" border>禁用</el-radio>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="addTruck">添加</el-button>
  </div>
</template>

<script>
import truck from '@/api/base/truck/index'

export default {
  name: 'add',
  data() {
    return {
      //车辆类型数据
      truckTypeData: [],
      //车队数据
      fleetData: [],
      truckForm: {
        truckTypeId: '',
        fleetId: '',
        brand: '',
        licensePlate: '',
        deviceGpsId: '',
        allowableLoad: '',
        allowableVolume: '',
        truckLicenseId: '',
        status: 1
      }
    }
  },
  methods: {
    addTruck() {
      truck.addTruck(this.truckForm).then(data => {
        this.$message({
          type: 'success',
          message: '车辆添加成功!',
          showClose: true
        })
        this.$router.push({path:'/truck-index'})
      })
    },
    //获取车辆类型
    getAllTruckType() {
      truck.getAllTruckType().then(data => {
        this.truckTypeData = data.data
      })
    },
    //获取车队
    getAllFleet() {
      truck.getAllFleet().then(data => {
        this.fleetData = data.data
      })
    }
  }, mounted() {
    this.getAllTruckType()
    this.getAllFleet()
  }
}
</script>

<style scoped>

</style>
